/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;

/**
 * @author zhaiyuxin
 * 
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class DocContants {

	//-------------��¼��ͬ�齨��class���-----------//
	public static String CLASS_TEXT = "";

	public static String CLASS_TEXTAREA = "";

	public static String CLASS_BUTTON = "";

	public static String CLASS_BUTTON_TEXT = "";

	public static String CLASS_CHECKBOX = "";

	public static String CLASS_RADIO = "";

	//-----------��¼��ͬ�İ�ť�����js�ű�------------//
	public static String BUTTON_EMPLOYEE_JS = "";

	public static String BUTTON_UNIT_JS = "";

	public static String BUTTON_DATE_JS = "";

	//-----------������Ͷ���---------//
	public static final String COMPONENT_TEXT = "text";

	public static final String COMPONENT_TEXTAREA = "textarea";

	public static final String COMPONENT_EMPLOYBUTTON = "employbutton";

	public static final String COMPONENT_DATEBUTTON = "datebutton";

	public static final String COMPONENT_UNITBUTTON = "unitbutton";

	public static final String COMPONENT_CHECKBOX = "checkbox";

	public static final String COMPONENT_RADIOBUTTON = "radiobutton";

	public static final String COMPONENT_TEXTEDIT = "textedit";

	public static final String COMPONENT_NUMBERTEXT = "numbertext";

	//-----------��ת�ַ���------------//
	public static final String CHAR_0 = "</";

	public static final String CHAR_1 = "<";

	public static final String CHAR_2 = "\"";

	public static final String CHAR_3 = ">";

	//-----------ת�ַ���-------------//
	public static final String PARSE_CHAR_0 = "##lt;##st;";

	public static final String PARSE_CHAR_1 = "##lt;";

	public static final String PARSE_CHAR_2 = "##quot;";

	public static final String PARSE_CHAR_3 = "##gt;";

	//-----------��¼���еĽ�������---------//
	public static final List holidayList = new ArrayList();

	public static final List workdayList = new ArrayList();

	//�������е���Ҫ�ⲿ���õ�js���ݺ�class����
	static {
		Properties pathProps = new Properties();
		Properties holidayProps = new Properties();
		ClassLoader cl = DocContants.class.getClassLoader();
		InputStream pathIs = cl.getResourceAsStream("patchjs.properties");
		if (pathIs != null) {
			try {
				pathProps.load(pathIs);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					pathIs.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		if (pathProps.get("employeebutton") != null)
			BUTTON_EMPLOYEE_JS = (String) pathProps.get("employeebutton");
		if (pathProps.get("employeebutton") != null)
			BUTTON_UNIT_JS = (String) pathProps.get("unitbutton");
		if (pathProps.get("employeebutton") != null)
			BUTTON_DATE_JS = (String) pathProps.get("datebutton");
		if (pathProps.get("textboxclass") != null)
			CLASS_TEXT = (String) pathProps.get("textboxclass");
		if (pathProps.get("textareaclass") != null)
			CLASS_TEXTAREA = (String) pathProps.get("textareaclass");
		if (pathProps.get("buttonclass") != null)
			CLASS_TEXTAREA = (String) pathProps.get("buttonclass");
		if (pathProps.get("buttontextclass") != null)
			CLASS_TEXTAREA = (String) pathProps.get("buttontextclass");
		if (pathProps.get("checkboxclass") != null)
			CLASS_TEXTAREA = (String) pathProps.get("checkboxclass");
		if (pathProps.get("radioclass") != null)
			CLASS_TEXTAREA = (String) pathProps.get("radioclass");

		InputStream holidayIs = cl.getResourceAsStream("holiday.properties");
		if (holidayIs != null) {
			try {
				holidayProps.load(holidayIs);
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					holidayIs.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}

		String year = String.valueOf(DateHelper.getYearBySystemTime());
		String holiday = holidayProps.getProperty("holiday");
		String workday = holidayProps.getProperty("workday");

		if (holiday != null) {
			String holidays[] = holiday.split(";");
			for (int i = 0; i < holidays.length; i++) {
				Date holidayDate = DateHelper.convertSimpleDateFormat(year
						+ "-" + holidays[i]);
				holidayList.add(holidayDate);
			}
		}

		if (workday != null) {
			String workdays[] = workday.split(";");
			for (int i = 0; i < workdays.length; i++) {
				Date workdayDate = DateHelper.convertSimpleDateFormat(year
						+ "-" + workdays[i]);
				workdayList.add(workdayDate);
			}
		}

	}

	/**
	 * ת�����й��ַ�
	 * 
	 * @param tHtml
	 * @return
	 */
	public static String parseHtml(String tHtml) {
		tHtml = tHtml.replaceAll(CHAR_0, PARSE_CHAR_0);
		tHtml = tHtml.replaceAll(CHAR_1, PARSE_CHAR_1);
		tHtml = tHtml.replaceAll(CHAR_2, PARSE_CHAR_2);
		tHtml = tHtml.replaceAll(CHAR_3, PARSE_CHAR_3);
		return tHtml;
	}

	/**
	 * ��ԭ��ת������ַ�
	 * 
	 * @param tHtml
	 * @return
	 */
	public static String deParseHtml(String tHtml) {
		tHtml = tHtml.replaceAll(PARSE_CHAR_0, CHAR_0);
		tHtml = tHtml.replaceAll(PARSE_CHAR_1, CHAR_1);
		tHtml = tHtml.replaceAll(PARSE_CHAR_2, CHAR_2);
		tHtml = tHtml.replaceAll(PARSE_CHAR_3, CHAR_3);
		return tHtml;
	}

	public static String parseJS(String componentName, String jScript) {
		String js = jScript.replaceAll("\\{0\\}", componentName);
		return js;
	}

}